﻿using Iworld.Administrator.Model;
using Iworld.Basis.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Iworld.Main.Impl
{

    /// <summary>
    /// 管理员的登陆信息
    /// </summary>
    public class AdministratorLoginInfo : ModelBase
    {
        #region 属性

        /// <summary>
        /// 身份标识
        /// </summary>
        public string Token { get; set; }

        /// <summary>
        /// 管理员信息的存储指针
        /// </summary>
        public int AdministratorId { get; set; }

        /// <summary>
        /// 上一次心跳的时间
        /// </summary>
        public DateTime LastHeartbeatTime { get; set; }

        /// <summary>
        /// 标识用户是否被T出
        /// </summary>
        public bool Hit { get; set; }

        #endregion

        #region 构造方法

        /// <summary>
        /// 实例化一个新的管理员的登陆信息
        /// </summary>
        public AdministratorLoginInfo()
        {

        }

        /// <summary>
        /// 实例化一个新的管理员的登陆信息
        /// </summary>
        /// <param name="administratorId">管理员信息的存储指针</param>
        public AdministratorLoginInfo(int administratorId)
        {
            this.Token = Guid.NewGuid().ToString("N");
            this.AdministratorId = administratorId;
            this.LastHeartbeatTime = DateTime.Now;
            this.Hit = false;
        }

        #endregion

        #region 方法

        /// <summary>
        /// 获取管理员信息
        /// </summary>
        /// <param name="db">数据库存储指针</param>
        /// <returns>返回管理员信息</returns>
        public Iworld.Administrator.Model.Administrator  GetUser(IModelToDbContextOfAdministrator db)
        {
            return db.Administrators.Find(this.AdministratorId);
        }

        /// <summary>
        /// 心跳
        /// </summary>
        public void Heartbeat()
        {
            this.LastHeartbeatTime = DateTime.Now;
        }

        #endregion
    }
}
